package com.animations;

import com.beans.BirdBean;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.bean.Switch;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;

public class PlayFlyAction extends Animation {

  private BirdBean birds;
  private ArrayList<Image> bird;
  private int birdSub = 1;

  public void loadBean() {
    this.birds = new BirdBean();
    getBeans().add(this.birds);
  }

  public void paint(Graphics g) {
    if (this.bird == null) this.bird = this.birds.getBird();
    g.drawImage(
      (Image) this.bird.get(this.birdSub),
      BirdBean.getBirdX(),
      BirdBean.getBirdY(),
      getMagicanvas()
    );
  }

  public void run() {
    boolean birdrisAble = true;
    while (Switch._isContinue()) {
      if (birdrisAble) this.birdSub += 1; else this.birdSub -= 1;
      if (this.birdSub == 0) birdrisAble = true;
      if (this.birdSub == 2) birdrisAble = !birdrisAble;
      try {
        Thread.sleep(110L);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      getMagicanvas().repaint();
    }
  }
}
